import VCData from '../interface/VCData'

export function getAveScore(list: VCData[]): number {
  let sum = 0
  for (let i = 0; i < list.length; i++) {
    sum += list[i]['总分']
  }
  if (sum) {
    return Number((sum / list.length).toFixed(2))
  } else {
    return 0
  }
}
export function filterMonth(list: VCData[], month: string): VCData[] {
  switch (month) {
    case '七月':
      return list.filter((item: VCData) => item['日期'] > 45106 && item['日期'] <= 45138)
    case '八月':
      return list.filter((item: VCData) => item['日期'] > 45138 && item['日期'] <= 45169)
    case '九月':
      return list.filter((item: VCData) => item['日期'] > 45169 && item['日期'] <= 45199)
    case '十月':
      return list.filter((item: VCData) => item['日期'] > 45199 && item['日期'] <= 45230)
    case '十一月':
      return list.filter((item: VCData) => item['日期'] > 45230 && item['日期'] <= 45260)
    case '十二月':
      return list.filter((item: VCData) => item['日期'] > 45260 && item['日期'] <= 45291)
    default:
      return []
  }
}
//按扣分项计算扣除分数之和
export function getVideoItemDeduct(sumData: VCData[]) {
  const progress = { name: '课程进度和顺序是否符合大纲(20)', value: 0 }
  const flow = { name: '是否按照授课流程上课(10)', value: 0 }
  const content = { name: '授课内容是否符合大纲(50)', value: 0 }
  const other = { name: '教学中存在的其他问题(10)', value: 0 }
  const video = { name: '视频质量(10)', value: 0 }
  for (let i = 0; i < sumData.length; i++) {
    progress.value += (20 - Number(sumData[i][progress.name]))
    flow.value += (10 - Number(sumData[i][flow.name]))
    content.value += (50 - Number(sumData[i][content.name]))
    other.value += (10 - Number(sumData[i][other.name]))
    video.value += (10 - Number(sumData[i][video.name]))
  }
  return {
    sum: [progress, flow, content, other, video],
    ave: [
      Number((Number(progress.value) / sumData.length).toFixed(2)),
      Number((Number(flow.value) / sumData.length).toFixed(2)),
      Number((Number(content.value) / sumData.length).toFixed(2)),
      Number((Number(other.value) / sumData.length).toFixed(2)),
      Number((Number(video.value) / sumData.length).toFixed(2))
    ]
  }
}
export function getCameraItemDeduct(sumData: VCData[]) {
  const teacher = { name: '讲师在班状态(30)', value: 0 }
  const share = { name: '课前分享情况(10)', value: 0 }
  const comeLate = { name: '学员迟到(20)', value: 0 }
  const leaveEarly = { name: '学员早退(10)', value: 0 }
  const serious = { name: '学员严重违纪(20)', value: 0 }
  const other = { name: '学员其他违纪(10)', value: 0 }
  for (let i = 0; i < sumData.length; i++) {
    teacher.value += (30 - Number(sumData[i][teacher.name]))
    share.value += (10 - Number(sumData[i][share.name]))
    comeLate.value += (20 - Number(sumData[i][comeLate.name]))
    leaveEarly.value += (10 - Number(sumData[i][leaveEarly.name]))
    serious.value += (20 - Number(sumData[i][serious.name]))
    other.value += (10 - Number(sumData[i][other.name]))
  }
  return {
    sum: [teacher, share, comeLate, leaveEarly, serious, other],
    ave: [
      Number((Number(teacher.value) / sumData.length).toFixed(2)),
      Number((Number(share.value) / sumData.length).toFixed(2)),
      Number((Number(comeLate.value) / sumData.length).toFixed(2)),
      Number((Number(leaveEarly.value) / sumData.length).toFixed(2)),
      Number((Number(serious.value) / sumData.length).toFixed(2)),
      Number((Number(other.value) / sumData.length).toFixed(2))
    ]
  }
}